import React, { useState ,useEffect} from "react";
import _ from 'lodash'
export default function useFormData({props,clearFormData,loadUrl,saveUrl,dealData}) {
  const [formData, setFormData] = useState(clearFormData);

  const formFieldPubPros = (proName) => {
    return {
      onChange: (e) => {
        setFormData({ ...formData, [proName]: e.target.value });
      },
      value: formData[proName],
    };
  };

  const formFieldPubProsForSelect = (proName) => {
    return {
      onChange: (v) => {
        setFormData({ ...formData, [proName]: v });
      },
      value: formData[proName],
    };
  };

 




  const saveData = (dealData) => {
    let dataClone = _.cloneDeep(formData);
    if(dealData){
      dataClone = dealData(dataClone);
    }
  }

  return {
    formFieldPubPros,
    formFieldPubProsForSelect,
    formData,
    setFormData,
  };
}
